package com.grao.waterschool.human.manager.service.impl;

import com.grao.waterschool.human.entiry.po.TSysTuser;
import com.grao.waterschool.human.entiry.po.TWschoolRole;
import com.grao.waterschool.human.entiry.po.TWschoolUserRoleLink;
import com.grao.waterschool.human.manager.service.RoleService;
import com.grao.waterschool.human.mapper.TWschoolRoleMapper;
import com.grao.waterschool.human.mapper.TWschoolUserRoleLinkMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class RoleServiceimpl implements RoleService {

    @Autowired
    private TWschoolUserRoleLinkMapper userRoleLinkMapper;

    @Autowired
    private TWschoolRoleMapper roleMapper;

    @Override
    public String setSuperAdmin(String teacherNum, String roleId) {
        TWschoolRole role = roleMapper.selectById(roleId);
        TSysTuser userMapper = roleMapper.selectUserById(teacherNum);
        if (role == null || userMapper == null) {
            return "设置失败";
        }
        userRoleLinkMapper.setRoleBySuperAdmin(teacherNum, roleId);
        return "设置成功," + userMapper.getTnickname() + "已成功修改为：" + role.getRoleName();
    }

    @Override
    public List<TWschoolRole> getRoleList() {
        List<TWschoolRole> list = new ArrayList<>();
        TWschoolRole jsRole = new TWschoolRole();
        jsRole.setId(1);
        jsRole.setRoleName("教师");
        TWschoolRole xsRole = new TWschoolRole();
        xsRole.setId(2);
        xsRole.setRoleName("学生");
        TWschoolRole qtRole = new TWschoolRole();
        qtRole.setId(3);
        qtRole.setRoleName("其他");
        list.add(jsRole);
        list.add(xsRole);
        list.add(qtRole);
        return list;
    }

    @Override
    public List<TWschoolUserRoleLink> getUserListByRoleId(String roleId) {
        return userRoleLinkMapper.getUserByRoleId(roleId);
    }

}
